﻿// -----------------------------------------------------------------------
// <copyright file="OneImgOperation.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace IPPackage.ImageAlgebra
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text;

    /// <summary>
    /// the one image operation in ima ge algebra
    /// </summary>
  public class OneImgOperation : ImageOperation.Operation
    {
        /// <summary>
        /// Make the image negative.
        /// </summary>
        /// <returns>new image after negative</returns>
        public Bitmap MakeNegative()
        {
            Bitmap newImg;
            try
            {
                this.NewBufferOfImage = new Color[BufferOfImage.GetLength(0), BufferOfImage.GetLength(1)];
                newImg = new Bitmap(BufferOfImage.GetLength(0), BufferOfImage.GetLength(1));
                for (int i = 0; i < BufferOfImage.GetLength(1); i++)
                {
                    for (int j = 0; j < BufferOfImage.GetLength(0); j++)
                    {
                        this.NewBufferOfImage[j, i] = Color.FromArgb((int)255 - BufferOfImage[j, i].R, (int)255 - BufferOfImage[j, i].G, (int)255 - BufferOfImage[j, i].B);
                        newImg.SetPixel(j, i, this.NewBufferOfImage[j, i]);
                    }
                }

                return newImg;
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }

            return null;
        }
    }
}
